var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/functionalComponent/antd/tooltip.tsx
var tooltip_exports = {};
__export(tooltip_exports, {
  Tooltip: () => Tooltip
});
module.exports = __toCommonJS(tooltip_exports);
var import_icons = require("@ant-design/icons");
var import_antd = require("antd");
var import_react = require("react");
var import_util = require("../../util");
function Tooltip(props) {
  const {
    defaultOpen = false,
    titleDep,
    title: propTitle,
    open: propOpen,
    onOpenChange: propOnOpenChange,
    overlayInnerStyle,
    overflow,
    color = "#fff",
    ...others
  } = props;
  const ref = (0, import_react.useRef)();
  const [open, setOpen] = (0, import_util.useRefState)(propOpen ?? defaultOpen);
  const [title, setTitle] = (0, import_util.useRefState)(import_util.iup.isFunction(propTitle) ? /* @__PURE__ */ React.createElement(import_icons.LoadingOutlined, null) : propTitle);
  const dep = import_util.iup.isFunction(propTitle) ? "" : propTitle;
  const getTitle = (0, import_util.useReturnCallback)(() => {
    return import_util.iup.isFunction(propTitle) ? propTitle() : propTitle;
  }, [titleDep, dep]);
  const onOpenChange = (v) => {
    if (v) {
      const targetEl = ref.current;
      if (overflow && targetEl) {
        if (targetEl.scrollWidth > targetEl.offsetWidth || targetEl.scrollHeight > targetEl.offsetHeight + 2) {
          setOpen(true);
        }
      } else {
        setOpen(true);
      }
    } else {
      setOpen(false);
    }
    propOnOpenChange == null ? void 0 : propOnOpenChange(v);
  };
  (0, import_util.useAsyncEffect)(async () => {
    if (open) {
      let ret = getTitle();
      if (import_util.iup.isPromise(ret)) {
        setTitle(/* @__PURE__ */ React.createElement(import_icons.LoadingOutlined, null));
        ret = await ret;
      }
      if (ret) {
        setTitle(ret);
      } else {
        setOpen(false);
      }
    }
  }, [open, titleDep]);
  const otherProps = { open, onOpenChange };
  const getPopupContainer = (triggerNode) => {
    ref.current = triggerNode;
    return (0, import_util.getGlobalContainer)();
  };
  return /* @__PURE__ */ React.createElement(
    import_antd.Tooltip,
    {
      getPopupContainer,
      mouseEnterDelay: 0.5,
      color,
      overlayInnerStyle: {
        color: ["#fff", "#FFFFFF", "#ffffff"].includes(color) ? "#333" : "#fff",
        ...overlayInnerStyle
      },
      destroyTooltipOnHide: true,
      ...otherProps,
      ...others,
      title
    }
  );
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  Tooltip
});
